<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <input id="username" />
    <button onclick="setValue()">设置文本框的值为"admin"</button>
    <button onclick="setReadOnly()">设置文本框只读</button>
    <button onclick="allowEdit()">设置文本框可以编辑</button>
    <script>
        var box = document.querySelector('#username');
        function setValue(){
            box.value = 'admin';
        }
        function setReadOnly(){
            // box.readonly = true
            box.setAttribute('readonly','readonly');
        }
        function allowEdit(){
            box.removeAttribute('readonly');
        }

    </script>
</body>

</html>